import React from 'react';
import { Form, DatePicker, Select, Button, Table } from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import { postDocCategoryStatistics, exportDocCategoryList } from "@/services/datastatistics";

const { RangePicker } = DatePicker;

class CategoryDetailStatistics extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      list: [],
      total: 0,
      loading: true
    }
  }

  componentDidMount() {
    if (this.props.onRef) {
      this.props.onRef(this);
    }
  }

  /**
   * 获取表格数据
   */
  getList = () => {
    const { dispatch, robotId, queryData } = this.props;
    this.setState({ loading: true }, async () => {
      let res = await postDocCategoryStatistics(queryData);
      console.log(res);
      this.setState({ loading: false, list: res })
    })
  }

  /**
   * 导出
   * @returns {*}
   */
  exportCategoryRecords = async () => {
    const { dispatch, queryData } = this.props;
    const res = await exportDocCategoryList(queryData);
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    const { list, loading } = this.state;
    const columns = [
      {
        title: '知识库分类',
        dataIndex: 'name',
        key: 'name',
        width: 400
      },
      {
        title: '命中次数',
        dataIndex: 'hit',
        key: 'hit',
        width: 200
      },
    ];

    return (
      <div>
        <div style={{ width: '100%', textAlign: 'right', marginBottom: 10 }}></div>
        <Table
          dataSource={list}
          columns={columns}
          loading={loading}
          pagination={false}
          rowKey={'id'}
          scroll={{ x: "auto" }}
        />
      </div>
    );
  }
}

export default connect(({ user }) => ({ // 全局数据
  currentUser: user.currentUser,
}))(Form.create()(CategoryDetailStatistics));
